<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends Admin{
	
	public function __construct()
    {
        parent::__construct();
		//$this->load->model("mcategory");
        $this->load->helper('content');
    }
	
	public function ajax_level1($id=null){
		$sub_level = $this->mcategory->getSubLevel($id);
		$option = '<option value="0">Please select...</option>';
		foreach($sub_level as $k=>$item){
			$option.= '<option value="'.$item['id'].'">'.$item['name'].'</option>';
		}
		$this->output->enable_profiler(FALSE); 
        $this->output->set_content_type('application/json')->set_output(json_encode($option));
	}
	public function combobox($id){
		$items = $this->mcategory->getSubCategory($id);
		$type = '<option value="">Please select..</option>'."\n";
		$need = '<option value="">Please select..</option>'."\n";
		foreach($items as $k=>$val){
			if($val['type']=='need'){
				$type.= '<option value="'.$val['id'].'">'.$val['name'].'</option>'."\n";
			}else {
				$need.= '<option value="'.$val['id'].'">'.$val['name'].'</option>'."\n";
			}
		}
		echo json_encode(array('type'=>$type,'need'=>$need));
		exit();
	}
    public function getSubCat($cat_id){
        echo $cat_id;die;
        $data=get_subcats($cat_id);
        var_dump($data);die;
        $option="";
        if(!empty($data)){
            foreach($data as $key=>$val){
                $option.='<option value="'.$val['id'].'">'.$val['name'].'</option>';
            }
        }
        echo json_encode(array('option'=>$option));
        exit();
    }

}